#ifndef __SYLAR_SOCKET_STREAM__
#define __SYLAR_SOCKET_STREAM__

#include "sylar/stream.h"
#include "sylar/socket.h"

namespace sylar{
	
class SocketStream : public Stream{
public:
	typedef std::shared_ptr<SocketStream> ptr;
	SocketStream(Socket::ptr sock, bool owner = true);
	~SocketStream();

	bool isConnected() const;
	
	virtual int read(void *buffer, size_t length);
	virtual int read(ByteArray::ptr ba, size_t length);
	virtual int write(const void* buffer, size_t length);
	virtual int write(ByteArray::ptr ba, size_t length);
	virtual void close();
	Socket::ptr getSocket() const {return m_socket;}

private:
	Socket::ptr m_socket;
	bool m_owner;
};

}

#endif